Skip to content

App map: the page reads the map from the bucket; the API sends only the overlays - #809

Merged
nambok merged 6 commits into
mainfrom
app-map-fast
Nov 23, 2026
Merged

nambok merged 6 commits into
mainfrom
app-map-fast

Conversation

@nambok

@nambok nambok commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The App map page often never loaded: GET /api/app-map could take tens of seconds on a large map (and hit the gateway's 30 s limit), because every request downloaded, parsed and re-sent the whole map, and placed each run's and finding's files by rebuilding a set of every file on the map once per file. Now the worker writes the page's copy and a small index at build time, the browser reads the copy straight from the bucket with a short-lived signed URL, and the API sends only Recent work and Health, placed with the index. This also folds in #805 (one build at a time per team), merged with main, so #805 can close.

Changes

  • Storage (common::app_map): view_key (the page's copy: Floorplan's checks labelled, read-only, stored as JSON with Content-Encoding: gzip) and index_key (MapIndex: folders to repositories, every file path on the map, each repository's main part, Floorplan's checks with their places), written by store_derived. Overlays are split into overlays(&MapIndex, runs, found) (a small payload: recent, and health with add, drop by id and summary) and apply_overlays; with_overlays is now those two, so the old behavior is the same by construction.
  • Worker: writes the copy and the index right after the map.
  • Gateway: GET /api/app-map reads the status, a HEAD of the map and the index (never the map), and answers with graph_url (signed GET, 15 min), graph_fallback (GET /api/app-map/graph, the stored bytes passed on unread, Content-Encoding: gzip), graph_at and overlays. A map with no index, or an index older than the map, gets them written once from the map (maps built before this). Plans' "why" are read eight at a time and only for runs on the map; Health's four sources are read at once. graph=0 still returns the status only.
  • Infra: the data bucket's CORS rule allows GET and HEAD next to PUT, from the same origins (the dashboard's, or any when unknown, since the signed URL is the credential). Self-hosted installs get it from the same storage stack.
  • AWS stand-in (tests only): keeps S3 objects in memory (put, get, head, with type, encoding and time).
  • App map: one build at a time per team, and a status the page can explain #805 (one build at a time, a status the page can explain), merged with main.
  • Chat's and /mcp's map lookups still read the whole map once per question (load_graph): they need the files, links and descriptions the index doesn't keep, and they are not on the page's path.
  • docs/app-map.md updated.

Verification

  • cargo fmt --all --check, cargo clippy -p common -p gateway -p worker --all-targets -- -D warnings: clean. cargo test -p common -p gateway -p worker: common 2932, gateway 1276, worker 2385 passed, 0 failed. infra: npm test 189 passed.
  • the_page_gets_an_address_for_the_map_and_small_overlays runs the real handler against the stand-in: no map, no address; a map built before this gets its copy (application/json, gzip, read-only) and index written once and not again; the URL is signed for the team's own key with a 900 s expiry; overlays match the copy's Health; /api/app-map/graph returns the stored bytes gzip-encoded, and another team's is not found.
  • overlays_from_the_index_match_the_map_with_its_overlays: the stored index and copy, with overlays laid over, equal the old with_overlays result for runs and findings together, each alone, and empty.
  • Page view, measured (a_page_view_reads_the_small_index_never_the_whole_map, debug build, one core):
    • synthetic 4,000-file map, 60 runs of 20 files and 200 findings: before 6.9 s of work and 2.56 MB sent; now 18 ms and 88 KB.
    • the same test can read a large map from disk (APP_MAP_BENCH_GRAPH, not committed) and shows the same drop from seconds to milliseconds; the browser reads a gzipped copy from the bucket, and the index is a few tens of KB gzipped.
    • through the handler (a_page_view_of_a_large_map_is_small_and_quick, 4,000 files, every call through the local stand-in): 19.6 ms, 739 bytes answered.
  • After this, a page view is a status read, a HEAD, a small index read, the runs and findings queries and up to 25 plan reads 8 at a time, so it should sit well under 1 s.

The App map's "Build the map again" pressed three times in nine seconds
queued three builds and the worker ran all three: the rebuild route wrote
the status with no condition (force) and the worker never checked.

- common::app_map: the build status carries a build id, the turn the
  worker is on, when the build started, its stage (reading, parts,
  describing, done), the repositories it reads, and when the current
  map was built from how many. Every write is versioned (a conditional
  put on v), and the decisions are pure: queue_next refuses while a
  build is queued or running (unless stuck past STALE_SECS); take_turn
  lets each message of a build run once (a duplicate, or another
  build's message, is skipped; the same message again after its worker
  went quiet past LEASE_SECS may retake it); progress/finished/failed
  only touch the build that is running. estimate_secs gives a usual
  range from the repository count.
- Gateway: POST /api/app-map/rebuild answers 409 already_building with
  the running build's status and sends nothing; 202 with the new
  status otherwise. GET /api/app-map returns started_at, stage,
  last_build, repos, estimate, built_at, built_repos and the server
  clock; graph=0 returns the status only (a HEAD for the map's date).
- Worker: each message takes its turn first and skips when it isn't
  the build's next; steps report their stage; messages carry the build
  id and turn; after_push uses the same one-build rule.
- Tests: three presses queue one build and send one message (fails on
  main: each press queued one), six concurrent presses start one,
  the worker skips a duplicate start and step, status_view, estimate.
  The AWS stand-in now records SQS messages and answers S3 reads.
…he overlays

- The worker writes the page's copy (view.json.gz, Content-Encoding gzip)
  and a small index (index.json.gz, common::app_map::MapIndex) with each
  map; a map built before them gets them on its first read.
- GET /api/app-map never reads or sends the whole map: the status, a
  15-minute signed GET for the copy (graph_url), the same bytes through
  GET /api/app-map/graph for a browser that can't reach the bucket, and
  Recent work and Health placed with the index (overlays).
- Overlays place files by lookup in the index, not by scanning the map's
  files for each one (map_path rebuilt a 3,800-entry set per file).
- Plans' why read eight at a time, for runs on the map only; Health's
  four sources read at once.
- Data bucket CORS allows GET and HEAD from the dashboard's origins.
- Includes #805 (one build at a time) merged with main.
- Tests: index round trip and equivalence with the old overlays, a page
  view on a 4,000-file map (common bench and through the handler), the
  AWS stand-in keeps S3 objects.
@nambok
nambok merged commit fef4ff3 into main Nov 23, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant